<?php

function pageSelector($results, $page, $limit){

if($results > $limit){

// rebuild queryString

$excludeFromQS = array('page','area','trade');

foreach ($_GET AS $key => $value){
if(strlen($key) > 0 && strlen($value) > 0)
$queryString.= (in_array($key,$excludeFromQS)) ? '' : '&amp;'.$key.'='.$value;
}

// recalculate page info

$pages = ceil($results / $limit);

$page = (isset($page)) ? $page - 1 : 0;

$tempPage = $page;
$tempPage1 = $page + 1;
$tempPage2 = $page + 2;

if($page != 0){
$pageSelector = '<a href="?page='.$tempPage.$queryString.'">&laquo; prev</a>&nbsp; &nbsp;';
}


$i = 1;

while($i <= $pages){
$pageSelector.=($i != $tempPage1) ? '<a href="?page='.$i.$queryString.'">'.$i.'</a>' : '<span style="font-weight: bold; color: #333333;">'.$i.'</span>' ;
$pageSelector.=($i != $pages) ? '&nbsp; | &nbsp;' : '' ;
$i++;
}

if($tempPage1 != $pages){
$pageSelector.= '&nbsp; &nbsp;<a href="?page='.$tempPage2.$queryString.'">next &raquo;</a>';
}



return $pageSelector;

}

}

?>